<template>
  <button @click="showDialog = true">打开</button>
  <div v-if="showDialog">
    <Teleport to="body">
      <div class="mask">
        <div class="dialog">
          我是一个对话框
          <button @click="showDialog = false">关闭</button>
        </div>
      </div>
    </Teleport>
  </div>
</template>

<script>
import { ref } from "vue";
export default {
  name: "Dilaog",
  setup() {
    const showDialog = ref(false);
    return {
      showDialog,
    };
  },
};
</script>

<style scoped>
.mask {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.1);
}

.dialog {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #fff;
  padding: 20px;
  background-color: aquamarine;
}
</style>
